#ifndef JSONRPCNOTIFICATION_H
#define JSONRPCNOTIFICATION_H

#include "JsonRpcMessage.h"
#include <QString>
#include <QVariant>
#include <QJsonObject>

/**
 * @brief JSON-RPC 2.0 Notification message class
 * 
 * This class represents a JSON-RPC 2.0 notification message with method name and optional parameters.
 * Notifications are requests without an ID field, meaning they don't expect a response.
 * The JSON object store in this class looks like:
 * ====================================
 * |  {                               |
 * |    jsonrpc:"2.0";                |
 * |    method: string;               |
 * |    params?: {                    |
 * |      [key: string]: unknown;     |
 * |    }                             |
 * |  }                               |
 * ====================================
 */
class JsonRpcNotification : public JsonRpcMessage
{
public:
    /**
     * @brief Construct a new JsonRpcNotification object
     */
    JsonRpcNotification();

    /**
     * @brief Construct a new JsonRpcNotification object with method name
     * @param method - The method name to call
     */
    explicit JsonRpcNotification(const QString& method);

    /**
     * @brief Construct a new JsonRpcNotification object with method name and parameters
     * @param method - The method name to call
     * @param params - The method parameters as JSON object
     */
    JsonRpcNotification(const QString& method, const QJsonObject& params);

    /**
     * @brief Destroy the JsonRpcNotification object
     */
    virtual ~JsonRpcNotification();

    /**
     * @brief Get the method name
     * @return QString - The method name
     */
    QString method() const;

    /**
     * @brief Set the method name
     * @param method - The method name to call
     */
    void setMethod(const QString& method);

    /**
     * @brief Get the method parameters
     * @return QJsonObject - The parameters as JSON object
     */
    QJsonObject params() const;

    /**
     * @brief Set the method parameters
     * @param params - The parameters as JSON object
     */
    void setParams(const QJsonObject& params);

    /**
     * @brief Check if the notification has parameters
     * @return bool - True if parameters are present, false otherwise
     */
    bool hasParams() const;

    /**
     * @brief Convert the notification to JSON object
     * @return QJsonObject - The JSON representation of the notification
     */
    QJsonObject toJson() const override;

    /**
     * @brief Create JsonRpcNotification from JSON object
     * @param json - The JSON object to parse
     * @param ok - Optional pointer to store parsing success status
     * @return JsonRpcNotification - The parsed notification object
     */
    static JsonRpcNotification fromJson(const QJsonObject& json, bool* ok = nullptr);

    /**
     * @brief Validate the notification structure
     * @return bool - True if notification is valid, false otherwise
     */
    bool isValid() const override;

private:
    QString mMethod;
    QJsonObject mParams;
};

#endif // JSONRPCNOTIFICATION_H
